import BaseQueryFilter from '@/components/BaseQueryFilter';
import RequestTable from '@/components/RequestTable';
import { ConfigProps } from '@/hooks/use-table-and-form-config/type';
import ContentCard from '@/page-components/ContentCard';
import api from '@/services';
import { Button, Form } from 'antd';
import { useRef } from 'react';
import usePageConfig from './usePageConfig';

const Index = () => {
  const [form] = Form.useForm();
  const tableRef = useRef<any>();
  const PageConfig = usePageConfig();

  const columns: ConfigProps[] = [
    {
      title: '序号',
      dataIndex: 'index',
      width: 80,
      fixed: 'left',
      type: 'input',
      render: (text: any, record: any, index: number) => {
        return index + 1;
      },
    },
    {
      title: '名称',
      dataIndex: 'name',
      type: 'input',
    },
    {
      title: '名称3',
      dataIndex: 'name2',
      type: 'input',
    },
  ];

  return (
    <>
      <BaseQueryFilter
        defaultCollapsed={false}
        form={form}
        onFinish={() => {
          tableRef.current.submit();
        }}
        onReset={() => {
          tableRef?.current?.reset();
        }}
        columns={columns}
      />
      <ContentCard
        title={PageConfig?.tableTitle}
        topLeft={<Button>新增</Button>}
        iconType="line"
        topRight={
          <>
            <Button>刷新</Button>
            <Button>刷新</Button>
          </>
        }
      >
        <RequestTable
          ref={tableRef}
          api={api.home.priceIndex.list}
          form={form}
          apiType="GET"
          columns={columns}
          submitFormat={(params: any) => {
            return {
              ...params,
              isTrue: true,
            };
          }}
        />
      </ContentCard>
    </>
  );
};
export default Index;
